/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.loli.hernandez.modelo;


import com.loli.hernandez.modelo.beans.Database;
import com.loli.hernandez.modelo.beans.DatabaseTable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author nestor
 */
public class DatabaseTablePeer {

    public static ArrayList<DatabaseTable> getTablesFromDatabase(
            DataManager dataManager, Database database) throws SQLException{
        ArrayList<DatabaseTable> tableList = new ArrayList<DatabaseTable>();
        //show full tables from northwind where `table_type` = 'base table'
        String sql = "show full tables from `" + database.getDatabaseName()
                + "` where `table_type` = 'base table'";
   
        ResultSet rs = dataManager.getResultSetFromQuery(sql);

        while (rs.next()) {
            DatabaseTable table = new DatabaseTable();
            table.setTableName(rs.getString(1));
            table.setTableType(rs.getString(2));
            tableList.add(table);
        }
        dataManager.fullDisposeResultSet(rs);
        return tableList;
    }
}
